class Solution {
public:
    vector<vector<bool>> vis;
    int dx[4] = {0,0,-1,1};
    int dy[4] = {-1,1,0,0};
    void dfs(int row , int col , vector<vector<char>>& grid)
    {
        int m = grid.size() , n = grid[0].size();
        for(int i = 0 ; i < 4 ; ++i)
        {
            int x = col + dx[i] , y = row + dy[i];
            if(x >= 0 && y >= 0 && x < n && y < m && vis[y][x] == false && grid[y][x] == '1')
            {
                vis[y][x] = true;
                dfs(y,x,grid);
            }
        }
    }
    int solve(vector<vector<char> >& grid) {
        //floodfill算法
        vis.resize(201,vector<bool>(201,false));
        
        if(vis[0][0] == false) cout << "1" << endl;
        int m = grid.size() , n = grid[0].size();
        int ret = 0;
        for(int i = 0 ; i < m ; ++i)
        {
            for(int j = 0 ; j < n ; ++j)
            {
                if(vis[i][j] == false && grid[i][j] == '1')
                {
                    vis[i][j] = true;
                    dfs(i,j,grid);
                    ++ret;
                }
            }
        }
        return ret;
    }
};